package com.eric.demo.netty.ch8;

import com.google.protobuf.InvalidProtocolBufferException;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ZhangGuangyin on 2018/9/9
 */
public class ProtoBufTest {

    public static void main(String[] argvs) throws InvalidProtocolBufferException {
        SubscribeReqProto.SubscribeReq.Builder builder = SubscribeReqProto.SubscribeReq
                .newBuilder();
        builder.setSubReqID(2);
        builder.setUserName("Lilinfeng");
        builder.setProductName("Netty Book For Protobuf");
        List<String> address = new ArrayList<>();
        address.add("NanJing YuHuaTai");
        address.add("BeiJing LiuLiChang");
        address.add("ShenZhen HongShuLin");
        builder.addAllAddress(address);
        SubscribeReqProto.SubscribeReq req = builder.build();

        byte[] result = req.toByteArray();
        SubscribeReqProto.SubscribeReq req2 = SubscribeReqProto.SubscribeReq.parseFrom(result);

        System.out.println(req);
        System.out.println(req2);
        System.out.println(req.equals(req2));

    }
}
